<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<!--  


-->


<body>
    <div id="root">
        <h1>个人信息</h1>

        <h2>姓名：{{name}}</h2>
        <h2>年龄：{{age}}</h2>

        <hr>

        <h1>学生信息</h1>
        <button @click="addsex">添加一个性别属性，默认值是男</button>
        <h2 v-if="student.sex">性别：{{student.sex}}</h2>

    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#root",
            data: {
                name: '张三',
                age: 20,

                student: {
                    name: 'Tom',
                    school: 'B站大学'
                }
            },
            methods: {
                addsex() {
                    // Vue.set(this.student, 'sex', '男')
                    this.$set(this.student, 'sex', '女')
                }
            }
        })
    </script>
</body>

</html>